home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bob_espo.swf / scripts / __Packages / CTRLGame.as < prev    next >
Text File  |  2013-04-24  |  14KB  |  447 lines

  1. class CTRLGame
  2. {
  3.    static var nOUT_POS_BTN_CACHE = -400;
  4.    static var nPOWERUP_BONUS_POINTS = 0;
  5.    static var nPOWERUP_GOOD_NOTE = 1;
  6.    static var nPOWERUP_FALSE_NOTE = 2;
  7.    static var nTURN_WALL = 0;
  8.    static var nTURN_WALL_INVERSE = 1;
  9.    static var nSLIDE_WALL_H = 2;
  10.    static var nSLIDE_WALL_V = 3;
  11.    static var nREVOLVER_WALL = 4;
  12.    static var nDIR_LEFT = 0;
  13.    static var nDIR_UP = 1;
  14.    static var nDIR_RIGHT = 2;
  15.    static var nDIR_DOWN = 3;
  16.    static var nLEVEL1 = 1;
  17.    static var nLEVEL2 = 2;
  18.    static var nDUMMY_DEPTH = 999999;
  19.    static var nMIN_DEPTH = 100012;
  20.    static var nDEPTH_FACTOR = 100;
  21.    static var nDIRT_WALL_ADD = 1;
  22.    static var nMOVING_WALL_ADD = 25;
  23.    static var nALGAE_ADD = 50;
  24.    static var nBUS_ADD = 76;
  25.    static var nJELLYFISH_ADD = 100;
  26.    static var nNB_THROW_SOUNDS = 5;
  27.    function CTRLGame(_mcRef, _nScore, _nLevel)
  28.    {
  29.       this.mcRef = _mcRef;
  30.       CTRLGame.oRef = this;
  31.       this.nScore = _nScore;
  32.       this.nCurrentLevel = _nLevel;
  33.       this.initLevel();
  34.    }
  35.    function cleanUp()
  36.    {
  37.       this.oGenerator.cleanUp();
  38.       this.oAtlantisBus.cleanUp();
  39.       this.oCenterScreen.cleanUp();
  40.       for(var i in this.aWalls)
  41.       {
  42.          this.aWalls[i].cleanUp();
  43.       }
  44.       for(var i in this.aDirtWalls)
  45.       {
  46.          for(var j in this.aDirtWalls[i])
  47.          {
  48.             this.aDirtWalls[i][j].cleanUp();
  49.          }
  50.       }
  51.       for(var i in this.aJellys)
  52.       {
  53.          this.aJellys[i].cleanUp();
  54.       }
  55.       for(var i in this.aAlguaes)
  56.       {
  57.          for(var j in this.aAlguaes[i])
  58.          {
  59.             this.aAlguaes[i][j].cleanUp();
  60.          }
  61.       }
  62.       delete this.oGenerator;
  63.       delete this.oAtlantisBus;
  64.       delete this.oCenterScreen;
  65.    }
  66.    function addObjectViaDummy(_mcDummy)
  67.    {
  68.       var _loc3_ = new Object();
  69.       _loc3_.x = 0;
  70.       _loc3_.y = 0;
  71.       _loc3_.x = _mcDummy._x;
  72.       _loc3_.y = _mcDummy._y;
  73.       _mcDummy._parent.localToGlobal(_loc3_);
  74.       _mcDummy.swapDepths(CTRLGame.nDUMMY_DEPTH);
  75.       _mcDummy.removeMovieClip();
  76.       return _loc3_;
  77.    }
  78.    function countdownPushBusGames()
  79.    {
  80.       if(this.nNbPushBusSandyLeft > 0)
  81.       {
  82.          this.nNbPushBusSandyLeft = this.nNbPushBusSandyLeft - 1;
  83.       }
  84.    }
  85.    function modifyTime(_nNewValue)
  86.    {
  87.       this.nSongsNumber = _nNewValue;
  88.    }
  89.    function blockEvents()
  90.    {
  91.       this.mcRef.mcCache._y = 0;
  92.       this.mcRef.mcShadow._visible = true;
  93.    }
  94.    function unBlockEvents()
  95.    {
  96.       this.mcRef.mcCache._y = CTRLGame.nOUT_POS_BTN_CACHE;
  97.       this.mcRef.mcShadow._visible = false;
  98.    }
  99.    function addToScore(_nNumber)
  100.    {
  101.       this.nScore += _nNumber;
  102.       Main.getRef().updateScoreField();
  103.    }
  104.    function substractToScore(_nNumber)
  105.    {
  106.       this.nScore -= _nNumber;
  107.       Main.getRef().updateScoreField();
  108.    }
  109.    function calculateDepth(_nY, _nAdd)
  110.    {
  111.       var _loc4_ = Math.round(_nY) * CTRLGame.nDEPTH_FACTOR + _nAdd + CTRLGame.nMIN_DEPTH;
  112.       return _loc4_;
  113.    }
  114.    function stopAnimElements()
  115.    {
  116.       for(var i in this.aDirtWalls)
  117.       {
  118.          for(var j in this.aDirtWalls[i])
  119.          {
  120.             this.aDirtWalls[i][j].doPause();
  121.          }
  122.       }
  123.       for(var i in this.aJellys)
  124.       {
  125.          this.aJellys[i].doPause();
  126.       }
  127.       for(var i in this.aAlguaes)
  128.       {
  129.          for(var j in this.aAlguaes[i])
  130.          {
  131.             this.aAlguaes[i][j].doPause();
  132.          }
  133.       }
  134.       this.oAtlantisBus.doPause();
  135.    }
  136.    function resumeAnimElements()
  137.    {
  138.       for(var i in this.aDirtWalls)
  139.       {
  140.          for(var j in this.aDirtWalls[i])
  141.          {
  142.             this.aDirtWalls[i][j].resumeAnim();
  143.          }
  144.       }
  145.       for(var i in this.aJellys)
  146.       {
  147.          this.aJellys[i].resumeAnim();
  148.       }
  149.       for(var i in this.aAlguaes)
  150.       {
  151.          for(var j in this.aAlguaes[i])
  152.          {
  153.             this.aAlguaes[i][j].resumeAnim();
  154.          }
  155.       }
  156.       this.oAtlantisBus.resumeAnim();
  157.    }
  158.    function addPowerUp(_nType, _mcItem)
  159.    {
  160.       var _loc4_ = new Object();
  161.       _loc4_.mcRef = _mcItem;
  162.       _mcItem._xscale = _mcItem._parent._parent._xscale;
  163.       _loc4_.nType = _nType;
  164.       var _loc5_ = this.oGenerator.getTabIndexByName(_mcItem._parent._parent._name);
  165.       this.aItems[_loc5_].push(_loc4_);
  166.    }
  167.    function addDirtWall(_mcDummy)
  168.    {
  169.       var _loc3_ = this.oGenerator.getTabIndexByName(_mcDummy._parent._parent._name);
  170.       var _loc4_ = this.addObjectViaDummy(_mcDummy);
  171.       this.aDirtWalls[_loc3_].push(new DirtWall(_loc4_.x,_loc4_.y));
  172.    }
  173.    function addJellyFish(_mcDummy)
  174.    {
  175.       var _loc3_ = this.addObjectViaDummy(_mcDummy);
  176.       this.aJellys.push(new RoamingJellyFish(_loc3_.x,_loc3_.y));
  177.    }
  178.    function addAlgae(_mcDummy)
  179.    {
  180.       var _loc3_ = this.oGenerator.getTabIndexByName(_mcDummy._parent._parent._name);
  181.       var _loc4_ = this.addObjectViaDummy(_mcDummy);
  182.       this.aAlguaes[_loc3_].push(new Algae(_loc4_.x,_loc4_.y));
  183.    }
  184.    function addActionWall(_nType, _mcDummy, _xScl)
  185.    {
  186.       var _loc5_ = this.addObjectViaDummy(_mcDummy);
  187.       this.aWalls.push(new ActionWall(_nType,_loc5_.x,_loc5_.y,_xScl));
  188.    }
  189.    function checkPowerUps()
  190.    {
  191.       var _loc2_ = this.oAtlantisBus.mcRef;
  192.       var _loc3_ = this.oGenerator.getTabIndex(_loc2_._x,_loc2_._y);
  193.       var _loc4_ = this.aItems[_loc3_];
  194.       for(var i in _loc4_)
  195.       {
  196.          if(_loc4_[i].mcRef.hitTest(_loc2_._x,_loc2_._y,true))
  197.          {
  198.             this.activatePowerUp(_loc4_[i].nType,_loc4_[i].mcRef);
  199.             delete _loc4_[i];
  200.             _loc4_.splice(Number(i),1);
  201.             break;
  202.          }
  203.       }
  204.    }
  205.    function checkDirtWalls()
  206.    {
  207.       var _loc2_ = this.oAtlantisBus.mcRef;
  208.       var _loc3_ = this.oGenerator.getTabIndex(_loc2_._x,_loc2_._y);
  209.       var _loc4_ = this.aDirtWalls[_loc3_];
  210.       for(var i in _loc4_)
  211.       {
  212.          if(_loc4_[i].mcRef.mcHit.hitTest(_loc2_.mcHit))
  213.          {
  214.             this.oCenterScreen.startBreakTheWall(_loc4_[i]);
  215.             _loc4_.splice(Number(i),1);
  216.             break;
  217.          }
  218.       }
  219.    }
  220.    function checkJellys()
  221.    {
  222.       var _loc2_ = this.oAtlantisBus.mcRef;
  223.       for(var i in this.aJellys)
  224.       {
  225.          if(this.aJellys[i].mcRef.mcHit.hitTest(_loc2_._x,_loc2_._y,true))
  226.          {
  227.             this.aJellys[i].stopRoaming();
  228.             this.oCenterScreen.startJellyFishSwarm(this.aJellys[i]);
  229.             this.aJellys.splice(Number(i),1);
  230.             break;
  231.          }
  232.       }
  233.    }
  234.    function checkAlgaes()
  235.    {
  236.       var _loc2_ = this.oAtlantisBus.mcRef;
  237.       var _loc3_ = this.oGenerator.getTabIndex(_loc2_._x,_loc2_._y);
  238.       var _loc4_ = this.aAlguaes[_loc3_];
  239.       for(var i in this.aAlguaes)
  240.       {
  241.          if(_loc4_[i].mcRef.mcHit.hitTest(_loc2_._x,_loc2_._y,true))
  242.          {
  243.             _loc4_[i].catchBus();
  244.             var _loc5_ = true;
  245.             if(this.nNbPushBusSandyLeft <= 0)
  246.             {
  247.                _loc5_ = false;
  248.             }
  249.             this.oCenterScreen.startPushTheBus(_loc4_[i],_loc5_);
  250.             _loc4_.splice(Number(i),1);
  251.             break;
  252.          }
  253.       }
  254.    }
  255.    function checkFinish()
  256.    {
  257.       var _loc2_ = this.oAtlantisBus.mcRef;
  258.       if(this.mcRef.mcStart.piece.mcFinish.hitTest(this.oAtlantisBus.mcRef._x,this.oAtlantisBus.mcRef._y,true) && !Main.getRef().Finished)
  259.       {
  260.          Main.getRef().winGame();
  261.       }
  262.    }
  263.    function isOkayToTurn(_mcHit)
  264.    {
  265.       var _loc3_ = true;
  266.       if(_mcHit.hitTest(this.oAtlantisBus.mcRef._x,this.oAtlantisBus.mcRef._y,true) || _mcHit.hitTest(this.oAtlantisBus.getMiCasePos().x,this.oAtlantisBus.getMiCasePos().y,true))
  267.       {
  268.          _loc3_ = false;
  269.       }
  270.       if(_loc3_)
  271.       {
  272.          for(var i in this.aJellys)
  273.          {
  274.             if(_mcHit.hitTest(this.aJellys[i].mcRef._x,this.aJellys[i].mcRef._y,true) || _mcHit.hitTest(this.aJellys[i].getMiCasePos().x,this.aJellys[i].getMiCasePos().y,true))
  275.             {
  276.                _loc3_ = false;
  277.                break;
  278.             }
  279.          }
  280.       }
  281.       return _loc3_;
  282.    }
  283.    function isOkayToTurnRevolver(_mcHit, _mcHitMore)
  284.    {
  285.       var _loc4_ = true;
  286.       if(_mcHit.hitTest(this.oAtlantisBus.mcRef._x,this.oAtlantisBus.mcRef._y,true) || (_mcHit.hitTest(this.oAtlantisBus.getMiCasePos().x,this.oAtlantisBus.getMiCasePos().y,true) || (_mcHitMore.hitTest(this.oAtlantisBus.mcRef._x,this.oAtlantisBus.mcRef._y,true) || _mcHitMore.hitTest(this.oAtlantisBus.getMiCasePos().x,this.oAtlantisBus.getMiCasePos().y,true))))
  287.       {
  288.          _loc4_ = false;
  289.       }
  290.       if(_loc4_)
  291.       {
  292.          for(var i in this.aJellys)
  293.          {
  294.             if(_mcHit.hitTest(this.aJellys[i].mcRef._x,this.aJellys[i].mcRef._y,true) || (_mcHit.hitTest(this.aJellys[i].getMiCasePos().x,this.aJellys[i].getMiCasePos().y,true) || (_mcHitMore.hitTest(this.aJellys[i].mcRef._x,this.aJellys[i].mcRef._y,true) || _mcHitMore.hitTest(this.aJellys[i].getMiCasePos().x,this.aJellys[i].getMiCasePos().y,true))))
  295.             {
  296.                _loc4_ = false;
  297.                break;
  298.             }
  299.          }
  300.       }
  301.       return _loc4_;
  302.    }
  303.    function isTouchingWall(_nFutureX, _nFutureY)
  304.    {
  305.       var _loc4_ = false;
  306.       for(var i in this.aWalls)
  307.       {
  308.          var _loc5_ = this.aWalls[i];
  309.          if(_loc5_.Type == CTRLGame.nREVOLVER_WALL)
  310.          {
  311.             if(_loc5_.Ref.mcHit.hitTest(_nFutureX,_nFutureY,true) || _loc5_.Ref.mcHitMore.hitTest(_nFutureX,_nFutureY,true))
  312.             {
  313.                _loc4_ = true;
  314.                break;
  315.             }
  316.          }
  317.          else if(_loc5_.Ref.mcHit.hitTest(_nFutureX,_nFutureY,true))
  318.          {
  319.             _loc4_ = true;
  320.             break;
  321.          }
  322.       }
  323.       return _loc4_;
  324.    }
  325.    function isJellyTouchingDirtWall(_nFutureX, _nFutureY)
  326.    {
  327.       var _loc4_ = false;
  328.       var _loc5_ = this.oGenerator.getTabIndex(_nFutureX,_nFutureY);
  329.       var _loc6_ = this.aDirtWalls[_loc5_];
  330.       for(var i in _loc6_)
  331.       {
  332.          if(_loc6_[i].mcRef.mcHit.hitTest(_nFutureX,_nFutureY,true))
  333.          {
  334.             _loc4_ = true;
  335.             break;
  336.          }
  337.       }
  338.       return _loc4_;
  339.    }
  340.    function isJellyTouchingAlguae(_nFutureX, _nFutureY)
  341.    {
  342.       var _loc4_ = false;
  343.       var _loc5_ = this.oGenerator.getTabIndex(_nFutureX,_nFutureY);
  344.       var _loc6_ = this.aAlguaes[_loc5_];
  345.       for(var i in _loc6_)
  346.       {
  347.          if(_loc6_[i].mcRef.mcHit.hitTest(_nFutureX,_nFutureY,true))
  348.          {
  349.             _loc4_ = true;
  350.             break;
  351.          }
  352.       }
  353.       return _loc4_;
  354.    }
  355.    function isJellyTouchingJelly(_nFutureX, _nFutureY, _oJelly)
  356.    {
  357.       var _loc5_ = false;
  358.       for(var i in this.aJellys)
  359.       {
  360.          if(this.aJellys[i] != _oJelly)
  361.          {
  362.             if(this.aJellys[i].mcRef.mcHit.hitTest(_nFutureX,_nFutureY,true))
  363.             {
  364.                _loc5_ = true;
  365.                break;
  366.             }
  367.          }
  368.       }
  369.       return _loc5_;
  370.    }
  371.    function get Screen()
  372.    {
  373.       return this.oCenterScreen;
  374.    }
  375.    function get Bus()
  376.    {
  377.       return this.oAtlantisBus;
  378.    }
  379.    function get Maze()
  380.    {
  381.       return this.oGenerator;
  382.    }
  383.    function get Songs()
  384.    {
  385.       return this.nSongsNumber;
  386.    }
  387.    function get Level()
  388.    {
  389.       return this.nCurrentLevel;
  390.    }
  391.    function get Score()
  392.    {
  393.       return this.nScore;
  394.    }
  395.    static function getRef()
  396.    {
  397.       return CTRLGame.oRef;
  398.    }
  399.    function activatePowerUp(_nType, _mcPowerUp)
  400.    {
  401.       switch(_nType)
  402.       {
  403.          case CTRLGame.nPOWERUP_BONUS_POINTS:
  404.             Controller.getRef().getSounds().playSound("GoodPowerUp_Collect",Controller.nSFX_VOLUME,1);
  405.             this.addToScore(LD.nBONUSPOINTS);
  406.             _mcPowerUp.swapDepths(7777);
  407.             _mcPowerUp.removeMovieClip();
  408.             break;
  409.          case CTRLGame.nPOWERUP_FALSE_NOTE:
  410.             Controller.getRef().getSounds().playSound("BadPowerUp_Collect",Controller.nSFX_VOLUME,1);
  411.             CTRLGame.getRef().Screen.getInterface().setToLife(LD.nFALSE_NOTE_VALUE);
  412.             _mcPowerUp.swapDepths(7777);
  413.             _mcPowerUp.removeMovieClip();
  414.             break;
  415.          case CTRLGame.nPOWERUP_GOOD_NOTE:
  416.             Controller.getRef().getSounds().playSound("GoodPowerUp_Collect",Controller.nSFX_VOLUME,1);
  417.             CTRLGame.getRef().Screen.getInterface().setToLife(LD.nGOOD_NOTE_VALUE);
  418.             _mcPowerUp.swapDepths(7777);
  419.             _mcPowerUp.removeMovieClip();
  420.       }
  421.    }
  422.    function winGame()
  423.    {
  424.       CTRLGame.getRef().Screen.getInterface().pauseTime();
  425.       Main.getRef().winGame();
  426.    }
  427.    function loseGame()
  428.    {
  429.       CTRLGame.getRef().Screen.getInterface().pauseTime();
  430.       Main.getRef().loseGame();
  431.    }
  432.    function initLevel()
  433.    {
  434.       this.aItems = [[],[],[],[],[],[],[],[],[],[]];
  435.       this.aWalls = new Array();
  436.       this.aAlguaes = [[],[],[],[],[],[],[],[],[],[]];
  437.       this.aDirtWalls = [[],[],[],[],[],[],[],[],[],[]];
  438.       this.aJellys = new Array();
  439.       this.nNbPushBusSandyLeft = LD.nNB_PUSHBUS_WITH_SANDY;
  440.       this.nSongsNumber = LD.getSongsMax(this.nCurrentLevel);
  441.       this.oGenerator = new MazeGenerator(this.mcRef);
  442.       this.oCenterScreen = new CenterScreen(this.mcRef.mcCenter);
  443.       this.oGenerator.generate();
  444.       this.oAtlantisBus = new AtlantisBus();
  445.    }
  446. }
  447.